<?php

class Controller_Style extends FLEA_Controller_Action
{
	var $tableAlbums;

	function Controller_Style(){		
		$this->tableAlbums = FLEA::getSingleton('Model_Albums');
	}	

	function actionList(){

		if (isset($_GET['id'])) {
            $styleId = (int)$_GET['id'];
        } else {
            redirect(url());
        }

		if ( $styleId == 0){

			FLEA::loadClass('Controller_Default');
			$runner = new Controller_Default();
			$runner->actionIndex();

		} else {

			$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
			
			$condition = array('style.style_id'=> $styleId);
			FLEA::loadClass('Controller_Pager');		
			$pager = new Controller_Pager($this->tableAlbums, $page-1,FLEA::getAppInf('pageSize'),$condition,null);

			$tableStyles = FLEA::getSingleton('Model_Styles');
			$style = $tableStyles->findAll(null,'style_id ASC');
			
			$smarty = &$this->_getView();
			$smarty->assign('styleArray', $style);
			$smarty->assign('styleId', $styleId);
			$smarty->assign('albumArray', $pager->findAll());
			$smarty->assign('albumRand', $this->tableAlbums->findAll(null,' rand()',10));
			$smarty->assign('page_info',$pager->getNavBar($this->_url()) );
			$smarty->display('default_index.html');
		}
	}
	
	
}
?>